home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
STANDALO
/
SQUARANT
/
SQUARANT.C
next >
Wrap
Text File
|
1990-11-15
|
10KB
|
374 lines
/***********************************************************************************
SIMPLE SYSTEMS¬ CLASS LIBRARY
SQuarantine.c
This is a class for virus protection. This object scans each
resource in the given resource file and compares the resource
profile against a developer defined table, a resource created
via a ResEdit tem plate. See the header file, SQuarantine.h,
for details.
READ THE SQUARANTINE ('Qnte') RESOURCE FORMAT NOTES - UNLESS
THE LAST RECORD IN THE 'Qnte' RESOURCE HAS A SIZE VALUE OF -1,
THE QUARANTINE METHODS WILL BE IN AN ENDLESS LOOP, ATTEMPTING
TO SCAN BEYOND THE QUARANTINE MAP IN MEMORY.
This source code is released for limited use, any commerical
product that uses this source code should acknowledge the author,
Schorschi LeRoy Decker, in the manual documentation and/or in the
'About...' window for his creative effort.
Version 1.0.0 11/10/90
Schorschi LeRoy Decker
Made some documentation changes.
Version 1.0.1 11/15/90
Schorschi LeRoy Decker
***********************************************************************************
IN NO WAY, SHAPE, OR FORM IS THIS FILE RELEASED TO BUSINESS ENTITIES THAT
CHARGE A FEE FOR DISTRIBUTION. FIRMS LIKE EDUCORP¬, WHICH CHARGE DISTRIBUTION
FEES FOR PUBLIC DOMAIN OR SHAREWARE PRODUCTS, MUST RECEIVE WRITTEN PERMISSION
FROM SIMPLE SYSTEMS¬ AND THE ORIGINAL AUTHOR OF THIS SOURCE CODE. BULLETIN BOARD
SYSTEMS AND ON-LINE SERVICES THAT CHARGE A CONNECT FEE ARE GIVEN LIMITED
PERMISSION FOR DOWNLOAD ACCESS BY MEMBERS. ANY VIOLATION OF THIS RESERVED RIGHT
OF LIMITED DISTRIBUTION WILL BE INFORCED TO THE FULLEST EXTENT OF THE LAW.
COPYRIGHT ⌐ 1990 SIMPLE SYSTEMS¬. ALL RIGHTS ARE RESERVED WORLD-WIDE.
SIMPLE SYSTEMS¬ is the trademark and property of SIMPLE SYSTEMS CONSULTING.
EDUCORP¬ is the trademark and property of EDUCORP Inc.
***********************************************************************************
Questions, comments, etc.
To: SIMPLE SYSTEMS
Schorschi LeRoy Decker
5067 Golden Ave.
Riverside, CA 92505
America-On-Line: Schorschi
CompuServe: 73020,546
Phone: (714) 597-1234 Please not after 11:00 pm (Pacific) or before
7:00 am (Pacific).
***********************************************************************************/
#include <Global.h>
#include <CError.h>
#include "SQuarantine.h"
/***********************************************************************************
IQuarantine()
Initialize quarantine object.
***********************************************************************************/
void SQuarantine::IQuarantine(int theResourceFile)
{
int theCurrentResourceFile;
theCurrentResourceFile = CurResFile();
if (theResourceFile != theCurrentResourceFile)
UseResFile(theResourceFile);
theQuarantineMap = (StringHandle)Get1Resource(rQuarantineType,
rQuarantineNumber);
theQuarantineFile = theResourceFile;
UseResFile(theCurrentResourceFile);
CheckResource((Handle)theQuarantineMap);
}
/***********************************************************************************
Dispose()
Dispose of the quarantine object.
***********************************************************************************/
void SQuarantine::Dispose()
{
if (theQuarantineMap != NULL)
ReleaseResource((Handle)theQuarantineMap);
inherited::Dispose();
}
/***********************************************************************************
Scan()
Loads each resource in the given resource file, and verify resource
according to the given flag values.
************************************************************************************/
Boolean SQuarantine::Scan(short theFlags)
{
int theCurrentResourceFile, theTypes, theTypeIndex,
theResources,theResourcesIndex;
long theType;
Handle theResource;
Boolean theResult;
theResult = FALSE;
if ((theQuarantineMap != NULL) && (theQuarantineFile != -1))
{
theCurrentResourceFile = CurResFile();
if (theQuarantineFile != theCurrentResourceFile)
UseResFile(theQuarantineFile);
theResult = TRUE;
theTypeIndex = 0;
theTypes = Count1Types();
while (((++theTypeIndex) <= theTypes) && theResult)
{
Get1IndType(&theType, theTypeIndex);
theResourcesIndex = 0;
theResources = Count1Resources(theType);
while (((++theResourcesIndex) <= theResources) && theResult)
{
theResource = Get1IndResource(theType, theResourcesIndex);
CheckResource(theResource);
if (theFlags % kTypeAndID)
{
theResult = TypeAndID(theResource);
if ((theFlags & kName) && theResult)
{
theResult = Name(theResource);
if ((theFlags & kSize) && theResult)
theResult = Size(theResource);
}
}
}
}
UseResFile(theCurrentResourceFile);
if (theTypeIndex <= theTypes)
theResult = FALSE;
}
return (theResult);
}
/***********************************************************************************
TypeAndID()
Scan the quarantine table for a match to the given type. Should a
match be found then the found field for the match is incremented by
the type flag.
***********************************************************************************/
Boolean SQuarantine::TypeAndID(Handle theResource)
{
QuarantinePtr thePointer;
long theType;
int theID;
Str255 theName;
Boolean theResult;
theResult = FALSE;
if ((theQuarantineMap != NULL) && (theResource != NULL) &&
(theQuarantineFile != -1))
{
GetResInfo(theResource, &theID, &theType, &theName);
HLock(theQuarantineMap);
thePointer = (QuarantinePtr)(*theQuarantineMap);
while (thePointer->size != -1)
{
if ((thePointer->type == theType) &&
(thePointer->id == theID))
{
thePointer->flags += kTypeAndID;
theResult = TRUE;
break;
}
thePointer = (QuarantinePtr)((StringPtr)thePointer +
(kQuarantineShift + thePointer->name[0] + 1));
}
HUnlock(theQuarantineMap);
}
return (theResult);
}
/***********************************************************************************
Name()
Scan the quarantine table for a match to the given type, id, and
name. Should a match be found then the found field for the match
is incremented by the ID flag.
***********************************************************************************/
Boolean SQuarantine::Name(Handle theResource)
{
QuarantinePtr thePointer;
long theType;
int theID;
Str255 theName;
Boolean theResult;
theResult = FALSE;
if ((theQuarantineMap != NULL) && (theResource != NULL) &&
(theQuarantineFile != -1))
{
GetResInfo(theResource, &theID, &theType, &theName);
HLock(theQuarantineMap);
thePointer = (QuarantinePtr)(*theQuarantineMap);
while (thePointer->size != -1)
{
if ((thePointer->type == theType) &&
(thePointer->id == theID) &&
(EqualString(thePointer->name, theName, TRUE, TRUE)))
{
thePointer->flags += kName;
theResult = TRUE;
break;
}
thePointer = (QuarantinePtr)((StringPtr)thePointer +
(kQuarantineShift + thePointer->name[0] + 1));
}
HUnlock(theQuarantineMap);
}
return (theResult);
}
/***********************************************************************************
Size()
Scan the quarantine table for a match to the given type, id, name, and
size. Should a match be found then the found field for the match is
incremented by the size flag.
***********************************************************************************/
Boolean SQuarantine::Size(Handle theResource)
{
QuarantinePtr thePointer;
long theType, theSize;
int theID;
Str255 theName;
Boolean theResult;
theResult = FALSE;
if ((theQuarantineMap != NULL) && (theResource != NULL) &&
(theQuarantineFile != -1))
{
GetResInfo(theResource, &theID, &theType, &theName);
theSize = SizeResource(theResource);
HLock(theQuarantineMap);
thePointer = (QuarantinePtr)(*theQuarantineMap);
while (thePointer->size != -1)
{
if ((thePointer->type == theType) &&
(thePointer->id == theID) &&
(EqualString(thePointer->name, theName, TRUE, TRUE)) &&
(thePointer->size == theSize))
{
thePointer->flags += kSize;
theResult = TRUE;
break;
}
thePointer = (QuarantinePtr)((StringPtr)thePointer +
(kQuarantineShift + thePointer->name[0] + 1));
}
HUnlock(theQuarantineMap);
}
return (theResult);
}
/***********************************************************************************
Missing()
Scan the quarantine table for resources that were not verified for type,
id, name, or size, based on the given flags value. This method should
be called after calling the Scan() method to determine if any resources
that were expected to be found are missing.
***********************************************************************************/
Boolean SQuarantine::Missed()
{
QuarantinePtr thePointer;
long theType, theSize;
int theID;
Str255 theName;
Boolean theResult;
theResult = FALSE;
if ((theQuarantineMap != NULL) && (theQuarantineFile != -1))
{
HLock(theQuarantineMap);
thePointer = (QuarantinePtr)(*theQuarantineMap);
while (thePointer->size != -1)
{
if (thePointer->flags == 0)
{
theResult = TRUE;
break;
}
thePointer = (QuarantinePtr)((StringPtr)thePointer +
(kQuarantineShift + thePointer->name[0] + 1));
}
HUnlock(theQuarantineMap);
}
return (theResult);
}
/***********************************************************************************
End of File - SQuarantine.c
***********************************************************************************/